package com.deam.imsdk.imsdk;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;

import com.alibaba.fastjson.JSONObject;
import com.deam.imsdk.elem.BaseElem;
import com.deam.imsdk.service.IMService;
import com.deam.imsdk.utils.Constants;


/**
 * Created by BLACK on 2018/4/18.
 */

public class MiPushClient {
    public static final String COMMAND_REGISTER = "register";
    private static Context mContext;

    /**
     * 注冊消息服务
     *
     * @param appContext
     */
    public static void registerPush(Context appContext) {
        mContext = appContext;
        Intent intent = new Intent(appContext, IMService.class);
        appContext.startService(intent);// 启动服务
    }

    /**
     * 给服务器发送消息
     */
    public static void sendMessage(String s) {
        if (mContext == null) return;
        Intent intent = new Intent();
        intent.setAction(Constants.IMS_BRPUSH_STRING);
        intent.putExtra(Constants.IMS_MESSAGE, s);
        mContext.sendBroadcast(intent);
    }

    public static Context getContext() {
        return mContext;
    }

    public static void sendMessage(@NonNull BaseElem elem) {
        sendMessage(elem.toMessageString());
    }
}
